<template>
<div class="box-padding add-project">
    <Form label-position="top">
        <div class="role-title">{{ $route.params.name }}</div>
    <Tabs>
        <TabPane label="基本信息">
                <Row :gutter="40">
                    <Col :span="8">
                    <FormItem label="项目全称" :required="$route.params.type == 'details' ? false : true">
                        <Input v-model="projectInfoData.name" placeholder="请输入项目全称" maxlength="60"
                        :disabled="$route.params.type == 'details' ? true : false" />
                    </FormItem>
                    </Col>
                    <Col :span="8">
                    <FormItem label="项目简称" :required="$route.params.type == 'details' ? false : true">
                         <Input v-model="projectInfoData.shortName" placeholder="请输入项目简称"
                        :disabled="$route.params.type == 'details' ? true : false" />
                    </FormItem>
                    </Col>
                </Row>
                <Row :gutter="40">
                    <Col :span="8">
                    <FormItem label="工程类型" :required="$route.params.type == 'details' ? false : true">
                        <Input v-model="projectInfoData.dictEngineeringTypeName" v-if="$route.params.type == 'details'" :disabled="$route.params.type == 'details' ? true : false" />
                    <Select v-if="$route.params.type != 'details'" v-model="projectInfoData.dictEngineeringType" ref="treeSelect" :disabled="$route.params.type == 'details' ? true : false">
                        <Option v-for="item in list" :value="item.code" :key="item.code">{{ item.title }}</Option>
                        <Tree :data="engineeringTypeList" style="padding-left:20px" @on-select-change="checkEng"></Tree>
                    </Select>
                    </FormItem>
                    </Col>
                    <Col :span="8"  v-if="isShowprofession">
                    <FormItem label="专业类型">
                        <Input v-model="projectInfoData.wbsName" v-if="$route.params.type == 'details'" :disabled="$route.params.type == 'details' ? true : false" />
                    <Select v-model="projectInfoData.wbsId" v-if="$route.params.type != 'details'" @on-open-change="getWbsList" not-found-text="暂无专业类型" ref="treeSelectWbs" placeholder="请选择" :disabled="$route.params.type == 'details' ? true : false">
                        <Option v-for="item in list1" :value="item.id" :key="item.id" style="display: none;">{{ item.title }}</Option>
                        <Tree :data="wbsList" ref="Tree" :load-data="loadData" style="padding-left:20px" v-if="wbsList.length > 0" @on-select-change="checkWbs"></Tree>
                    </Select>
                    </FormItem>
                    </Col>
                </Row>
                <Row :gutter="40">
                    <Col :span="8">
                    <FormItem label="项目类型">
                        <Select v-model="projectInfoData.dictProjectType" :disabled="$route.params.type == 'details' ? true : false">
                        <Option v-for="item in proTypeList" :value="item.code" :key="item.code">{{ item.name }}</Option>
                    </Select>
                    </FormItem>
                    </Col>
                    <Col :span="8">
                    <FormItem label="风险等级" :required="$route.params.type == 'details' ? false : true">
                        <Select v-model="projectInfoData.dictRiskGrade" :disabled="$route.params.type == 'details' ? true : false">
                        <Option v-for="item in leveList" :value="item.code" :key="item.code">{{ item.name }}</Option>
                    </Select>
                    </FormItem>
                    </Col>
                </Row>
                <Row :gutter="40">
                    <Col :span="8">
                    <FormItem label="施工状态" :required="$route.params.type == 'details' ? false : true">
                        <Select v-model="projectInfoData.dictConstructionState" :disabled="$route.params.type == 'details' ? true : false">
                        <Option v-for="item in constructionStateList" :value="item.code" :key="item.code">{{ item.name }}</Option>
                    </Select>
                    </FormItem>
                    </Col>
                </Row>
                <Row :gutter="40">
                    <Col :span="8">
                    <FormItem label="计划开工时间" :required="$route.params.type == 'details' ? false : true">
                        <DatePicker v-model="projectInfoData.planedStartDate" placeholder="请选择"
                        :disabled="$route.params.type == 'details' ? true : false" type="date"></DatePicker>
                    </FormItem>
                    </Col>
                    <Col :span="8">
                    <FormItem label="计划完工时间" :required="$route.params.type == 'details' ? false : true">
                        <DatePicker v-model="projectInfoData.planedEndDate" placeholder="请选择"
                        :disabled="$route.params.type == 'details' ? true : false" type="date"></DatePicker>
                    </FormItem>
                    </Col>
                </Row>
                <Row>
                    <Col :span="16">
                        <FormItem label="所在地区" :required="$route.params.type == 'details' ? false : true">
                            <Row :gutter="40">
                                <!-- 省选择 -->
                                <Col span="8">
                                    <Select v-model="projectInfoData.provinceId"
                                    :disabled="$route.params.type == 'details' ? true : false"
                                    @on-change="changeProvince(projectInfoData.provinceId)">
                                    <Option
                                        v-for="(item, index) in provinceArr"
                                        :key="index" :value="item.id">{{ item.name }}</Option>
                                    </Select>
                                </Col>
                                <!-- 市选择 -->
                                <Col span="8">
                                    <Select v-model="projectInfoData.cityId" v-if="showCity"
                                    :disabled="$route.params.type == 'details' ? true : false"
                                    @on-change="changeCity(projectInfoData.cityId)">
                                    <Option
                                        v-for="(item, index) in citiesArr" :key="index"
                                        :value="item.id">{{ item.name }}</Option>
                                    </Select>
                                </Col>
                                <!-- 区选择 -->
                                <Col span="8">
                                    <Select v-model="projectInfoData.districtId" v-if="showCounty"
                                    :disabled="$route.params.type == 'details' ? true : false">
                                    <Option v-for="(item, index) in countyArr"
                                        :key="index" :value="item.id">{{ item.name }}</Option>
                                    </Select>
                                </Col>
                            </Row>
                        </FormItem>
                    </Col>
                </Row>
                <Row :gutter="40">
                    <Col :span="12">
                    <FormItem label="详细地址" :required="$route.params.type == 'details' ? false : true">
                        <Input v-model="projectInfoData.address" placeholder="请输入详细地址"
                        :disabled="$route.params.type == 'details' ? true : false" />
                    </FormItem>
                    </Col>
                    <Col :span="4" class="locationIcon">
                        <Icon type="md-pin" @click="showMap" v-if="$route.params.type != 'details'"/>
                    </Col>
                </Row>
                <Row>
                    <Col>
                    <FormItem label="路线平面图" :required="$route.params.type == 'details' ? false : true">
                        <Row :gutter="40">
                            <Col :span="12">
                                <Input v-model="fileNames" :readonly="roadReadonly" placeholder="选择附件上传"
                                :disabled="$route.params.type == 'details' ? true : false" />
                            </Col>
                            <Col :span="4" class="upload-my-file">
                            <Upload
                                v-if="$route.params.type != 'details'"
                                :format="['jpg','jpeg','png']"
                                :max-size="5120"
                                :before-upload="handleBeforeUpload"
                                :on-success="handleSuccessZz" multiple type="drag"
                                :on-format-error="handleFormatError"
                                :on-exceeded-size="handleMaxSize"
                                :show-upload-list="showUploadList"
                                :action="uploadAction"
                                :disabled="$route.params.type == 'details' ? true : false">
                                <i-button>
                                    <Icon type="ios-cloud-upload-outline" size="18"/>
                                    &nbsp;&nbsp;附件上传
                                </i-button>
                            </Upload>
                            <span
                                v-if="$route.params.type=='details'"
                                @click="download(projectInfoData.fileInfo[0].id)"
                                class="button-class">
                                下载文件</span>
                            </Col>
                            <Col :span="8"></Col>
                        </Row>
                    </FormItem>
                    </Col>
                </Row>
                <Row :gutter="40">
                    <Col :span="16">
                    <FormItem label="项目概述">
                        <Input placeholder="请输入项目概述" v-model="projectInfoData.description" type="textarea"
                        :disabled="$route.params.type == 'details' ? true : false" />
                    </FormItem>
                    </Col>
                    <Col :span="8"></Col>
                </Row>
        </TabPane>
        <TabPane label="管理信息">
                <Row>
                    <Col :span="8">
                    <FormItem label="项目经理" :required="$route.params.type == 'details' ? false : true">
                        <Input v-model="projectInfoData.projectManage.pmName" placeholder="请输入项目经理"
                        :disabled="$route.params.type == 'details' ? true : false" />
                    </FormItem>
                    </Col>
                </Row>
                <Row>
                    <Col :span="8">
                    <FormItem label="联系电话" :required="$route.params.type == 'details' ? false : true">
                        <Input v-model="projectInfoData.projectManage.tel" placeholder="请输入联系电话"
                        :disabled="$route.params.type == 'details' ? true : false" />
                    </FormItem>
                    </Col>
                </Row>
                <Row>
                    <Col :span="8">
                    <FormItem label="中标单位" :required="$route.params.type == 'details' ? false : true">
                        <Input
                        v-model="projectInfoData.projectManage.winningEntName"
                        v-if="$route.params.type == 'details'"
                        :disabled="$route.params.type == 'details' ? true : false" />
                    <Select v-model="projectInfoData.projectManage.winningEntId"
                        v-if="$route.params.type != 'details'"
                        :disabled="$route.params.type == 'details' ? true : false"
                        @on-open-change="getTreeEnterprise"
                        ref="enterpristTreeSelect">
                        <Option v-for="item in list3"
                        :value="item.code" :key="item.code">{{ item.title }}</Option>
                        <Tree :data="allEnterpriseList" style="padding-left:20px"
                        @on-select-change="checkEnterpriseTree"></Tree>
                    </Select>
                    </FormItem>
                    </Col>
                </Row>
                <Row>
                    <Col :span="8">
                    <FormItem label="管理单位" :required="$route.params.type == 'details' ? false : true">
                        <Input v-model="projectInfoData.projectManage.manageEntName"
                    v-if="$route.params.type == 'details'"
                    :disabled="$route.params.type == 'details' ? true : false" />
                    <Select v-model="projectInfoData.projectManage.manageEntId"
                    v-if="$route.params.type != 'details'"
                    :disabled="$route.params.type == 'details' ? true : false"
                    @on-open-change="getTreeEnterprise"
                    ref="enterpristTreeSelect1">
                        <Option v-for="item in list2"
                        :value="item.code" :key="item.code">{{ item.title }}</Option>
                        <Tree :data="allEnterpriseList" style="padding-left:20px"
                        @on-select-change="checkEnterpriseTree1"></Tree>
                    </Select>
                    </FormItem>
                    </Col>
                </Row>

        </TabPane>
    </Tabs>
    <div class="role-bottom" v-show="$route.params.type != 'details'">
        <Button type="primary" @click="save">保存</Button>
        <Button style="margin-left:20px;" @click="cancel">取消</Button>
    </div>
    <Modal v-model="mapModal" title="位置定位" @on-visible-change="modalSwitch" @on-ok="ok" @on-cancel="closeMap">
        <div style="height:300px" id="container" tabindex="0"></div>
        <div class="toolbar">地址: {{ address }}</div>
    </Modal>
    </Form>

</div>
</template>

<script>
import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import {
    mapMutations
} from 'vuex'
import crudMixin from '../../../mixins/crudMixin'
import { setInterval } from 'timers'
import Utils from '../../../common/util'

export default {
    components: {
        Treeselect
    },
    mixins: [crudMixin],
    data() {
        return {
            engineeringTypeList: [], //工程类型
            projectInfoData: {
                dictEngineeringType: '',
                projectManage: {}
            }, //数据保存
            obj:{
                dictEngineeringType: '',
                projectManage: {}
            },
            list: [], //工程类型
            list1: [], //专业类型
            list2: [], //管理单位
            list3: [], //中标单位
            wbsList: [], //专业类型列表
            allEnterpriseList: [], //所有机构列表
            allEnterpriseList1: [], //所有机构列表

            proTypeList: [], //项目类型
            provinceArr: [], //省
            citiesArr: [], //市
            countyArr: [], //区
            ledgerObj: {},
            showCity: true,
            showCounty: true,
            mapModal: false, //地图对话框
            roadReadonly:false,//路线平面图输入框
            fileNames: '',
            showUploadList: false,
            uploadAction: process.env.VUE_APP_FILE_SERVER_URL + 'file/uploadFile',
            downloadAction:process.env.VUE_APP_FILE_SERVER_URL+'file/downFile',
            params: {
                whereMap: {
                    parentId: '0'
                }
            },
            file: null,
            loadingStatus: false,
            searchOption: {
                city: '上海',
                citylimit: true
            },
            mapCenter: [121.53, 31.22],
            lng: '',
            lat: '',
            lnglat: [],
            address: '',
            ruleValidate: {
                name: [{
                    required: true,
                    message: 'The name cannot be empty',
                    trigger: 'blur'
                }],
            },
            provinceId:'',
            cityId:'',
            districtId:'',
            isShowprofession:false
        }
    },
    watch: {},
    mounted() {
        // this.init() //地图初始化
        this.isExistWBS()  //判断是否需要专业类型
        this.getEngineeringType()
        this.regionList()
        this.dictTypeList('RISK_GRADE') //获取风险类型
        this.getConstructionState('CONSTRUCTION_STATE') //获取施工状态
        this.getProType() //获取项目类型
        //this.getTreeEnterprise()
        if (this.$route.params.type != 'add' && this.$route.params.id) {
            this.getProjectInfoDetail()
        } else {
            this.projectInfoData = {}
            this.fileNames = ''
            this.projectInfoData.projectManage = {}
        }
        if(this.$route.params.type === 'edit'){
            this.roadReadonly = true
        }
    },
    methods: {
        //判断是否需要专业类型
        isExistWBS(){
            this.$api.WorkstationLedger.existWBS().then(res => {
                if (res.code == 200) {
                    this.isShowprofession = res.data
                } else {
                    this.$Message.warning(res.message)
                }
            })
        },
        modalSwitch(e) {
            setTimeout(() => {
                if (e) {
                    if (window.modalMap) {
                        let cityName
                        if (this.projectInfoData.provinceId) {
                            cityName = this.provinceArr.filter(
                                p => p.id === this.projectInfoData.provinceId
                            )[0].name
                        }
                        if (cityName.includes('市')) {
                            window.modalMap.setCity(cityName)
                        } else if (this.projectInfoData.cityId) {
                            cityName = this.citiesArr.filter(
                                c => c.id === this.projectInfoData.cityId
                            )[0].name
                            window.modalMap.setCity(cityName)
                        }
                    } else {
                        this.init()
                    }
                }
            }, 0)
        },
        //地图初始化
        init() {
            let map = new AMap.Map('container', {
                resizeEnable: true,
                zoom: 10,
                lang: 'zh'
            })

            let that = this
            AMap.plugin(['AMap.Geocoder'], () => {
                let geocoder = new AMap.Geocoder({
                    radius: 1000
                })
                let marker = new AMap.Marker()
                function regeoCode(lnglat) {
                    map.add(marker)
                    marker.setPosition(lnglat)
                    geocoder.getAddress(lnglat, function (status, result) {
                        if (status === 'complete' && result.regeocode) {
                            that.address = result.regeocode.formattedAddress
                        } else {
                            this.$Message.warning('根据经纬度查询地址失败')
                        }
                    })
                }
                // 绑定事件
                map.on('click', function (ev) {
                    regeoCode([ev.lnglat.lng, ev.lnglat.lat])
                    that.lng = ev.lnglat.lng.toString()
                    that.lat = ev.lnglat.lat.toString()
                })
            })

            AMap.plugin(['AMap.ToolBar', 'AMap.Scale', 'AMap.Geocoder'], () => {
                map.addControl(new AMap.Scale())
            })
            window.modalMap = map
        },
        ...mapMutations(['closeTag']),
        //地图弹窗
        showMap() {
            this.mapModal = true
            this.init()
        },
        //文件下载
        download(id){
            window.open(this.downloadAction+'/'+id);
        },
        //获取工程类型
        getEngineeringType() {
            let code = 'ENGINEERING_TYPE'
            this.$api.projectInquiry.getTreeByTypeCode(code).then(res => {
                if (res.code == 200) {
                    this.engineeringTypeList = res.data
                    this.engineeringTypeList.forEach(item => {
                        item.title = item.name
                        if (item.children.length > 0) {
                            item.children = this.getCheildItem(item.children)
                        }
                    })
                } else {
                    this.$Message.error(res.data.msg)
                }
            })
        },
        //递归树状结构
        getCheildItem(data) {
            let item = data
            const arr = []
            item.forEach(val => {
                let obj = {}
                obj.title = val.name
                obj.code = val.code
                obj.children = []
                if (val.children.length > 0) {
                    obj.children = this.getCheildItem(val)
                }
                arr.push(obj)
            })
            return arr
        },
        checkEng(data) {
            this.projectInfoData.wbsId = ''
            if (data[0].children.length > 0) {
                this.$Message.warning('请选择最子级节点')
            } else {
                this.list = []
                let code = data[0].code
                let title = data[0].title
                this.list.push({
                    code,
                    title
                })
                this.projectInfoData.dictEngineeringType = code
                this.projectInfoData.dictEngineeringTypeName = title
                this.$refs.treeSelect.visible = false
            }
        },
        //获取专业类型
        getWbsList(data) {
            if (data) {
                if (this.projectInfoData.dictEngineeringType) {
                    let res = {
                        currentPage: 1,
                        pageSize: 99999,
                        whereMap: {
                            dictEngineeringType: this.projectInfoData.dictEngineeringType,
                            parentId: 0
                        }
                    }
                    this.$api.projectInquiry.getWbsList(res).then(res => {
                        if (res.code == 200) {
                            res.data.resultObject.map(r => {
                                this.$set(r, 'title', r.name)
                                if (r.hasChildren) {
                                    this.$set(r, 'children', [])
                                    this.$set(r, 'loading', false)
                                }
                            })
                            this.wbsList = [{
                                title: '标准WBS',
                                parentId: 0,
                                hasChildren: false,
                                loading: false,
                                expand: true,
                                children: res.data.resultObject
                            }]
                        } else {
                            this.$Message.error(res.data.msg)
                        }
                    })
                } else {
                    this.$Message.warning('请先选择工程类型')
                }
            }
        },
        loadData(item, callback) {
            let params = {
                currentPage: 1,
                pageSize: 99999,
                whereMap: {
                    dictEngineeringType: this.projectInfoData.dictEngineeringType,
                    parentId: item.id
                }
            }
            let data = []
            this.$api.projectInquiry.getWbsList(params).then(res => {
                if (res.code == 200) {
                    callback(this.getTree(res.data.resultObject))
                } else {
                    this.$Message.error(res.data.msg)
                }
            })
        },
        getTree(tree) {
            return tree.map(node => {
                node.title = node.name
                if (node.hasChildren) {
                    node.loading = false
                    node.children = []
                }
                return node
            })
        },
        checkWbs(data) {
            this.list1 = []
            let id = data[0].id
            let title = data[0].title
            this.list1.push({
                id,
                title
            })
            this.projectInfoData.wbsId = id
            this.projectInfoData.wbsName = title
            this.$refs.treeSelectWbs.visible = false
        },

        //获取机构树
        getTreeEnterprise() {
            this.$api.projectInfo.getTreeEnterprise().then(res => {
                if (res.code == 200) {
                    this.allEnterpriseList = res.data
                    this.allEnterpriseList.forEach(item => {
                        item.title = item.name
                        if (item.children.length > 0) {
                            item.children = this.getCheild(item.children)
                        }
                    })
                } else {
                    this.$Message.error(res.data.msg)
                }
            })
        },
        getCheild(tree) {
            return tree.map(node => {
                node.title = node.name
                if (node.hasChildren) {
                    node.loading = false
                    node.children = []
                }
                return node
            })
        },
        checkEnterpriseTree(data) {
            this.list3 = []
            if(!data[0].objectId){
                this.$Message.warning(`请选择具体的${data[0].title}！`)
                return;
            }
            let code = data[0].objectId
            let title = data[0].title
            this.list3.push({
                code,
                title
            })
            this.projectInfoData.projectManage.winningEntId = code
            this.projectInfoData.projectManage.winningEntName = title

            this.$refs.enterpristTreeSelect.visible = false
            data[0].expand = false
        },
        checkEnterpriseTree1(data) {
            this.list2 = []
            if(!data[0].objectId){
                this.$Message.warning(`请选择具体的${data[0].title}！`)
                return;
            }
            let code = data[0].objectId
            let title = data[0].title
            this.list2.push({
                code,
                title
            })
            this.projectInfoData.projectManage.manageEntId = code
            this.projectInfoData.projectManage.manageEntName = title

            this.$refs.enterpristTreeSelect1.visible = false
        },
        regionList() {
            let parmes = {
                whereMap:{
                    parentId:'0'
                }
            }
            this.$api.companyOrganization.regionList(parmes).then(resp => {
                if (resp.code == 200) {
                    this.provinceArr = resp.data.resultObject;
                } else {
                    this.$Message.warning(resp.message)
                }
            })
        },
        regionListShi(id) {
            if(id){
                let parmes = {
                    whereMap:{
                        parentId:id
                    }
                }
                this.$api.companyOrganization.regionList(parmes).then(resp => {
                    if (resp.code == 200) {
                        this.citiesArr = resp.data.resultObject;
                    } else {
                        this.$Message.warning(resp.message)
                    }
                })
            }else{
                this.citiesArr = []
            }
        },
        regionListQu(id) {
            if(id){
                let parmes = {
                    whereMap:{
                        parentId:id
                    }
                }
                this.$api.companyOrganization.regionList(parmes).then(resp => {
                    if (resp.code == 200) {
                        this.countyArr = resp.data.resultObject;
                    } else {
                        this.$Message.warning(resp.message)
                    }
                })
            }else{
                this.countyArr = []
            }
        },
        changeProvince(id) {
            this.citiesArr = []
            this.countyArr = []
            this.$set(this.projectInfoData,'cityId','')
            this.$set(this.projectInfoData,'districtId','')
            this.regionListShi(id)
        },
        changeCity(id) {
            this.countyArr = []
            this.$set(this.projectInfoData,'districtId','')
            this.regionListQu(id)
        },
        //文件上传前的判断
        handleBeforeUpload(file){
            console.log(111,file)
        },
        // 上传成功回调
        handleSuccessZz(res) {
            let obj = {
                path:res.fileUrls,
                name:res.fileNames,
                id:res.fileIds,
            }
            this.projectInfoData.fileInfo = []
            this.projectInfoData.fileInfo.push(obj)
            this.$Message.success('上传成功')
            this.roadReadonly = true
            this.projectInfoData.routePlanId = res.fileIds
            this.fileNames = res.fileNames
        },
        //格式错误提示
        handleFormatError (file) {
            this.$Message.warning('上传的文件格式不对')
            this.fileNames = ''
        },
        //大小错误提示
        handleMaxSize (file) {
            this.$Message.warning('大小超过5M')
        },
        // 取消
        cancel() {
            this.closetab()
            this.$router.push({
                path: '/project-management/project-info'
            })
        },
        // 保存修改/新增
        save() {
            if (!this.projectInfoData.name) {
                this.$Message.warning("项目全称不能为空！");
                return;
            }
            if (this.projectInfoData.name.length > 60) {
                this.$Message.warning("项目全称不能超过60个字符！");
                return;
            }
            if (!this.projectInfoData.shortName) {
                this.$Message.warning("项目简称不能为空！");
                return;
            }
            if (this.projectInfoData.shortName.length > 60) {
                this.$Message.warning("项目简称不能超过60个字符！");
                return;
            }
            if (!this.projectInfoData.dictEngineeringType) {
                this.$Message.warning("工程类型不能为空！");
                return;
            }
            if (!this.projectInfoData.dictRiskGrade) {
                this.$Message.warning("风险等级不能为空！");
                return;
            }
            if (!this.projectInfoData.dictConstructionState) {
                this.$Message.warning("施工状态不能为空！");
                return;
            }
            if (!this.projectInfoData.planedStartDate) {
                this.$Message.warning("计划开工时间不能为空！");
                return;
            }
            if (!this.projectInfoData.planedEndDate) {
                this.$Message.warning("计划完工时间不能为空！");
                return;
            }
            if (!this.projectInfoData.provinceId) {
                this.$Message.warning("所在地区（省）不能为空！");
                return;
            }
            // if (!this.projectInfoData.cityId) {
            //     this.$Message.warning("所在地区（市）不能为空！");
            //     return;
            // }
            // if (!this.projectInfoData.districtId) {
            //     this.$Message.warning("所在地区（区）不能为空！");
            //     return;
            // }
            if (!this.projectInfoData.address) {
                this.$Message.warning("详细地址不能为空！");
                return;
            }
            if (this.projectInfoData.address && this.projectInfoData.address.length > 60) {
                this.$Message.warning("详细地址不能超过60个字符！");
                return;
            }
            if (!this.projectInfoData.routePlanId) {
                this.$Message.warning("路线平面图不能为空！");
                return;
            }
            if (this.projectInfoData.description && this.projectInfoData.description.length > 500) {
                this.$Message.warning("项目概述不能超过500个字符！");
                return;
            }
            if (!this.projectInfoData.projectManage.pmName) {
                this.$Message.warning("项目经理不能为空！");
                return;
            }
            if (this.projectInfoData.projectManage.pmName.length > 60) {
                this.$Message.warning("项目经理不能超过60个字符！");
                return;
            }
            if (!this.projectInfoData.projectManage.tel) {
                this.$Message.warning("联系电话不能为空！");
                return;
            }
            if (this.projectInfoData.projectManage.tel.length > 11) {
                this.$Message.warning("联系电话不能超过11个字符！");
                return;
            }
            if (!this.$regex.telRegEx(this.projectInfoData.projectManage.tel)) {
                this.$Message.warning('联系电话格式不正确')
                return;
            }
            if (!this.projectInfoData.projectManage.winningEntId) {
                this.$Message.warning("中标单位不能为空！");
                return;
            }
            if (!this.projectInfoData.projectManage.manageEntId) {
                this.$Message.warning("管理单位不能为空！");
                return;
            }
            if (this.$route.params.type == 'edit') {
                this.$api.projectInfo
                    .editProjectInfo(this.projectInfoData)
                    .then(resp => {
                        if (resp.code == 200) {
                            this.$Message.success('修改成功')
                            Utils.$emit('demo', 'msg')
                            this.closetab()
                        } else {
                            this.$Message.warning(resp.message)
                        }
                    })
            } else {
                this.$api.projectInfo
                    .addProjectInfo(this.projectInfoData)
                    .then(resp => {
                        if (resp.code == 200) {
                            this.$Message.success('添加成功')
                            Utils.$emit('demo', 'msg')
                            this.closetab()
                        } else {
                            this.$Message.warning(resp.message)
                        }
                    })
            }
        },
        // 编辑关闭
        closetab() {
            this.closeTag({
                name: this.$route.params.type == 'add' ? 'projectInfo-add' : this.$route.params.type == 'edit' ? 'projectInfo-edit' : 'projectInfo-detail',
                params: {
                    name: this.$route.params.name,
                    id: this.$route.params.id,
                    type: this.$route.params.type
                }
            })
        },
        ok() {
            this.mapModal = false
            this.projectInfoData.address = this.address
            let data = {
                longitude:this.lng,
                latitude:this.lat
            }
            this.$api.projectInquiry.getAddressCodeAndDetail(data).then(resp=>{
                if(resp.code == 200){
                    this.projectInfoData.provinceId = resp.data.provinceId
                    this.projectInfoData.cityId = resp.data.cityId
                    this.projectInfoData.districtId = resp.data.districtId
                    this.regionListShi(this.projectInfoData.provinceId)
                    this.regionListQu(this.projectInfoData.cityId)
                    // setTimeout(()=>{
                    //     if(this.projectInfoData.districtId == undefined){
                    //         console.log('bbbb',this.projectInfoData.districtId)
                    //         this.$set(this.projectInfoData,'districtId',resp.data.districtId)
                    //         console.log('cccc',this.projectInfoData)
                    //         console.log('cccc',this.projectInfoData.districtId)

                    //     }else{
                    //         console.log('aaa',this.projectInfoData.districtId)
                    //     }
                    // },2000)

                }
            })
        },
        closeMap() {
            this.mapModal = false
        },
        // 项目详情
        getProjectInfoDetail() {
            if (this.$route.params.name === '日志详情') {
                this.$api.operationLog
                    .getOperationLogDetail(this.$route.params.id)
                    .then(res => {
                        if (res.code === 200) {
                            this.projectInfoData = JSON.parse(res.data.params)
                            this.projectInfoData.planedEndDate = this.$time(
                                new Date(this.projectInfoData.planedEndDate),
                                'yyyy-MM-dd'
                            )
                            this.projectInfoData.planedStartDate = this.$time(
                                new Date(this.projectInfoData.planedStartDate),
                                'yyyy-MM-dd'
                            )
                            this.fileNames = this.projectInfoData.fileInfo[0].name
                            this.regionListShi(this.projectInfoData.provinceId)
                            this.regionListQu(this.projectInfoData.cityId)
                            if (this.$route.params.type === 'details') {
                                this.projectInfoData.dictEngineeringType =
                                    this.projectInfoData.dictEngineeringTypeName
                                this.projectInfoData.wbsId = this.projectInfoData.wbsName
                                this.projectInfoData.projectManage.manageEntId =
                                    this.projectInfoData.projectManage.manageEntName
                                this.projectInfoData.projectManage.winningEntId =
                                    this.projectInfoData.projectManage.winningEntName
                            }
                        } else {
                            this.$Message.error(res.message)
                        }
                    })
            } else {
                this.$api.projectInfo
                    .getProjectInfoDetail(this.$route.params.id)
                    .then(res => {
                        if (res.code === 200) {
                            this.projectInfoData = res.data
                            this.regionListShi(res.data.provinceId)
                            this.regionListQu(res.data.cityId)
                            this.projectInfoData.cityIds = res.data.cityId
                            this.projectInfoData.districtIds = res.data.districtId
                            this.fileNames = res.data.fileInfo[0].name
                            if (this.$route.params.type === 'details') {
                                this.projectInfoData.dictEngineeringType =
                                    res.data.dictEngineeringTypeName
                                this.projectInfoData.wbsId = res.data.wbsName
                                this.projectInfoData.projectManage.manageEntId =
                                    res.data.projectManage.manageEntName
                                this.projectInfoData.projectManage.winningEntId =
                                    res.data.projectManage.winningEntName
                            } else {
                                this.list = [{
                                    code: res.data.dictEngineeringType,
                                    title: res.data.dictEngineeringTypeName
                                }]
                                this.list1 = [{
                                    id: res.data.wbsId,
                                    title: res.data.wbsName
                                }]
                                this.list2 = [{
                                    code: res.data.projectManage.manageEntId,
                                    title: res.data.projectManage.manageEntName
                                }]
                                this.list3 = [{
                                    code: res.data.projectManage.winningEntId,
                                    title: res.data.projectManage.winningEntName
                                }]
                            }

                        } else {
                            this.$Message.error(res.message)
                        }
                    })
            }
        }
    }
}
</script>

<style scoped>
.role-title {
    color: #333;
    font-size: 20px;
    height: 50px;
    line-height: 50px;
    font-weight: bold;
    margin-bottom: 20px;
}

.asterisk:before {
    content: '*';
}

.ivu-select {
    display: block;
}

.ivu-date-picker {
    display: block;
}

.ivu-row {
    width: 100%;
}

.role-bottom {
    padding: 20px 0;
    display: flex;
    justify-content: center;
}

.amap-demo {
    height: 300px;
}

.search-box {
    position: absolute;
    top: 25px;
    left: 20px;
}

.amap-page-container {
    position: relative;
}

.locationIcon {
    position: relative;
    top: 22px;
}

.locationIcon .ivu-icon-md-pin {
    font-size: 26px;
}
/* .add-project .ivu-tabs{
    overflow:visible;
} */
.add-project .ivu-tabs-ink-bar{
    z-index: 0;
}
</style>
